﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DB_test
{
    static class GenerateSqlQuerys
    {
        public static string UpdateQuery(Dictionary<string, object> data, string id)
        {
            var keysAndValues = "";
            var index = "";
            int i = 0;
            foreach (var keyAndValue in data)
            {
                if (keyAndValue.Key == id)
                    index = String.Format("{0}='{1}'", keyAndValue.Key, keyAndValue.Value);
                else
                {
                    if (i++ != 0)
                        keysAndValues += ", ";
                    keysAndValues += String.Format("{0}='{1}'", keyAndValue.Key, keyAndValue.Value.ToString().Trim());
                }
            }
            return string.Format("{0} where {1}", keysAndValues, index);
        }

        public static string InsertQuery(Dictionary<string, object> data, string id)
        {
            var keys = "";
            var values = "";
            int i = 0;
            foreach (var keysAndValues in data)
            {
                if (!keysAndValues.Key.Equals(id))
                {
                    if (i++ != 0)
                    {
                        keys += ", ";
                        values += ", ";
                    }
                    keys += String.Format("{0}", keysAndValues.Key);
                    values += String.Format("'{0}'", keysAndValues.Value.ToString());
                }
            }
            return String.Format("({0}) output Inserted.{1} values ({2})", keys, id, values);
        }

    }
}
